<template>
	<view class="content">
		<navTop :title="navtop.title" :isHeight="false" :tipsShow="false" hasBgc="#fff" :color="navtop.color" :isBack="true" ></navTop>
		<view class="content-box" :style="{paddingTop:barHeight+'rpx'}">
		</view>
		<view class="content-view">
			<view class="title-search">
				<image :src="'/static/search.png'" mode="" class="title-search__icon"></image>
				<input class="tips" v-model="keyWord" placeholder="Search" @confirm="seachKey"/>
			</view>
			<view class="content-list">
				<view class="list-item" @click="gotoUser(v, i)" v-for="(v, i) in followingList" :key="i">
					<image :src="v.head" mode="aspectFit" class="list-item__img"></image>
					<view class="list-item__text">
						<view class="list-item__title">
							{{v.name || ''}}
						</view>
						<view class="list-item__info">
							{{v.tips || ''}}
						</view>
					</view>
					<view class="list-item__btn" @click.stop="followUser(v, v.followState)">
						{{v.followState ? 'unFollow' : 'Follow'}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
import navTop from '@/components/nav-title.vue';

	export default {
		components: {
			navTop
		},
		data() {
			return {
				barHeight: 0,
				navtop: {
					title: 'Follow',
					color: '#000'
				},
				type: 0,
				keyWord: '',
				followingList: []
			}
		},
		onLoad(e) {
			this.type = e.type
			if (e.type == 0) {
				this.getList()
			} else {
				this.getList2()
			}
		},
		created() {
			this.isBarHeight999().then((statusBarHeight)=>{
				this.barHeight = statusBarHeight + 180
			})
		},
		methods: {
			getList2() {
				this.$http('get', '/app/me/follower', {
					keyword: this.keyword || ''
				}).then((res) => {
					if (res.success) {
						console.log(res)
						this.followingList = res.data
					}
				})
			},
			getList() {
				this.$http('get', '/app/me/following', {
					keyword: this.keyword || ''
				}).then((res) => {
					if (res.success) {
						console.log(res)
						this.followingList = res.data
					}
				})
			},
			seachKey(){
				if (this.type == 0) {
					this.getList()
				}
			},
			followUser(v, followState) {
				this.$http('post', '/app/follow', {
					dynamicId: '',
					accountId: v.id
				}, {
					'Content-Type': 'application/x-www-form-urlencoded'
				}).then((res) => {
					if (res.success) {
						if (followState == 1) {
							v.followState = 0
						} else {
							v.followState = 1
						}
					}
				})
			},			
			gotoUser(v) {
				uni.navigateTo({
					url: '/pages/me/userDetail?id=' + v.id
				})
			}
		}
	}
</script>

<style lang="less">
.content {
	background-color: #fff;
	// padding: 0 30px;
	min-height: 100vh;
}
.content-box {
	font-size: 40rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #1F1F1F;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 40rpx;
	.content-box__btn {
		display: inline-block;
		padding: 16rpx 32rpx;
		font-size: 28rpx;
		color: #fff;
		background: #0078FF;
		border-radius: 18px;
	}
}
.content-view {
	width: 690rpx;
	min-height: 100vh;
	margin: auto;
	background: #FFFFFF;
	box-shadow: 0px 4px 12px 0px rgba(55, 58, 64, 0.08);
	border-radius: 8rpx;
	padding: 40rpx;
}
.title-search {
	width: 100%;
	height: 64rpx;
	line-height: 64rpx;
	background: rgba(31, 31, 31, 0.05);
	border-radius: 36rpx;
	padding-left: 40rpx;
	box-sizing: border-box;
	font-size: 30rpx;
	font-family: Avenir-Book, Avenir;
	font-weight: normal;
	color: rgba(31, 31, 31, 0.45);
	display: flex;
	justify-content: flex-start;
	align-items: center;
	margin-bottom: 20rpx;
	.title-search__icon {
		width: 30rpx;
		height: 30rpx;
		margin-right: 24rpx;
	}
}
.list-item {
	height: 144rpx;
	background: #FFFFFF;
	border-bottom: 1px solid #f1f1f1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	.list-item__img {
		width: 96rpx;
		height: 96rpx;
		margin-right: 20rpx;
		border-radius: 50%;
	}
	.list-item__text {
		width: 334rpx;
	}
	.list-item__title {
		width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		margin-bottom: 8rpx;
		font-size: 32rpx;
		color: #1F1F1F;
	}
	.list-item__info {
		width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		margin-bottom: 8rpx;
		font-size: 22rpx;
		font-family: Helvetica;
		color: rgba(31, 31, 31, 0.45);
	}
	.list-item__btn {
		width: 140rpx;
		height: 56rpx;
		text-align: center;
		line-height: 58rpx;
		background: #FFFFFF;
		border-radius: 36rpx;
		border: 1px solid #0078FF;
		font-size: 24rpx;
		font-family: Helvetica;
		color: #0078FF;
	}
}
</style>
